package cn.terminus.web.customer.contractsellclauseinfo.controller;

import cn.terminus.web.customer.contractsellclauseinfo.form.ContractSellClauseInfoNewForm;
import cn.terminus.web.customer.contractsellclauseinfo.form.ContractSellClauseInfoEditForm;
import cn.terminus.web.customer.contractsellclauseinfo.form.ContractSellClauseInfoQueryForm;
import cn.terminus.web.customer.contractsellclauseinfo.form.ContractSellClauseInfoDeleteForm;
import cn.terminus.web.customer.contractsellclauseinfo.form.ContractSellClauseInfoGetsForm;
import cn.terminus.client.customer.contractsellclauseinfo.param.ContractSellClauseInfoNewParam;
import cn.terminus.client.customer.contractsellclauseinfo.param.ContractSellClauseInfoEditParam;
import cn.terminus.client.customer.contractsellclauseinfo.param.ContractSellClauseInfoQueryParam;
import cn.terminus.client.customer.contractsellclauseinfo.param.ContractSellClauseInfoDeleteParam;
import cn.terminus.client.customer.contractsellclauseinfo.param.ContractSellClauseInfoGetsParam;
import cn.terminus.client.customer.contractsellclauseinfo.result.ContractSellClauseInfoResult;
import cn.terminus.client.customer.contractsellclauseinfo.service.ContractSellClauseInfoService;
import cn.terminus.result.common.result.TerminusResult;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.web.customer.common.AbstractTerminusController;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.exception.ServiceException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cn.terminus.result.common.util.BeanCopyUtils;
import cn.terminus.result.common.context.TerminusCallContext;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.List;

/**
 * 合同售卖条款信息(ContractSellClauseInfo)控制层
 *
 * @author makejava
 * @version 1.0.0
 * @apiDefine ContractSellClauseInfo 合同售卖条款信息
 * @since 2021-07-21 11:17:37
 */
@RestController
// todo 请修改path
@RequestMapping("/contractSellClauseInfo")
@Api(value = "合同售卖条款信息(ContractSellClauseInfo)控制层")
public class ContractSellClauseInfoController extends AbstractTerminusController {
    /**
     * 服务对象
     */
    @Resource
    private ContractSellClauseInfoService contractSellClauseInfoService;

    /**
     * @api {POST} /contractSellClauseInfo/add 合同售卖条款信息新增
     * @apiVersion 1.0.0
     * @apiGroup ContractSellClauseInfo
     * @apiName 合同售卖条款信息新增
     * @apiDescription 合同售卖条款信息新增
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Double} totalPrice  总价
     * @apiParam (RequestBody) {Double} unitPrice  单价
     * @apiParam (RequestBody) {String} paymentMethodCodeCode  付款方式code
     * @apiParam (RequestBody) {Integer} paymentDay  一次性付款/按揭付款天数范围
     * @apiParam (RequestBody) {String} paymentTypeCode  一次性付款/按揭付款时间类型 工作日，自然日，指定几号
     * @apiParam (RequestBody) {Double} mortgagePaymentPercentage  按揭付款支付百分比
     * @apiParam (RequestBody) {Integer} mortgagePaymentLastDay  按揭付款自合同签订之日起XX日内付贷款
     * @apiParam (RequestBody) {Double} propertyFee  物业管理费
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {String} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":"[]"}
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖条款信息新增", httpMethod = "POST")
    public TerminusResult<String> add(@RequestBody ContractSellClauseInfoNewForm form) {
        ContractSellClauseInfoNewParam param = BeanCopyUtils.copyProperties(form, ContractSellClauseInfoNewParam.class);
        try {
            return contractSellClauseInfoService.add(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("新增合同售卖条款信息失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("新增合同售卖条款信息失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }


    /**
     * @api {POST} /contractSellClauseInfo/edit 合同售卖条款信息编辑
     * @apiVersion 1.0.0
     * @apiGroup ContractSellClauseInfo
     * @apiName 合同售卖条款信息编辑
     * @apiDescription 合同售卖条款信息编辑
     * @apiParam (RequestBody) {Long} id  ID
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Double} totalPrice  总价
     * @apiParam (RequestBody) {Double} unitPrice  单价
     * @apiParam (RequestBody) {String} paymentMethodCodeCode  付款方式code
     * @apiParam (RequestBody) {Integer} paymentDay  一次性付款/按揭付款天数范围
     * @apiParam (RequestBody) {String} paymentTypeCode  一次性付款/按揭付款时间类型 工作日，自然日，指定几号
     * @apiParam (RequestBody) {Double} mortgagePaymentPercentage  按揭付款支付百分比
     * @apiParam (RequestBody) {Integer} mortgagePaymentLastDay  按揭付款自合同签订之日起XX日内付贷款
     * @apiParam (RequestBody) {Double} propertyFee  物业管理费
     * @apiSuccess (Success 200) {String} code    状态码（00000000表示请求成功）
     * @apiSuccess (Success 200) {Boolean} success    成功
     * @apiSuccess (Success 200) {String} message    结果消息
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖条款信息编辑", httpMethod = "POST")
    public TerminusResult<Boolean> edit(@RequestBody ContractSellClauseInfoEditForm form) {
        ContractSellClauseInfoEditParam param = BeanCopyUtils.copyProperties(form, ContractSellClauseInfoEditParam.class);
        try {
            return contractSellClauseInfoService.update(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("修改合同售卖条款信息失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("修改合同售卖条款信息失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellClauseInfo/delete 合同售卖条款信息删除
     * @apiVersion 1.0.0
     * @apiGroup ContractSellClauseInfo
     * @apiName 合同售卖条款信息删除
     * @apiDescription 合同售卖条款信息删除
     * @apiParam (RequestBody) {String[]} ids  合同售卖条款信息ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":true}
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖条款信息删除", httpMethod = "POST")
    public TerminusResult<Boolean> delete(@RequestBody ContractSellClauseInfoDeleteForm form) {
        ContractSellClauseInfoDeleteParam param = BeanCopyUtils.copyProperties(form, ContractSellClauseInfoDeleteParam.class);
        try {
            return contractSellClauseInfoService.delete(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("删除合同售卖条款信息失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("删除合同售卖条款信息失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellClauseInfo/gets 合同售卖条款信息详情
     * @apiVersion 1.0.0
     * @apiGroup ContractSellClauseInfo
     * @apiName 合同售卖条款信息详情
     * @apiDescription 合同售卖条款信息详情
     * @apiParam (RequestBody) {String[]} ids  合同售卖条款信息ids
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    合同售卖条款信息列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Double} data.datas.totalPrice  总价
     * @apiSuccess (Success 200) {Double} data.datas.unitPrice  单价
     * @apiSuccess (Success 200) {String} data.datas.paymentMethodCodeCode  付款方式code
     * @apiSuccess (Success 200) {Integer} data.datas.paymentDay  一次性付款/按揭付款天数范围
     * @apiSuccess (Success 200) {String} data.datas.paymentTypeCode  一次性付款/按揭付款时间类型 工作日，自然日，指定几号
     * @apiSuccess (Success 200) {Double} data.datas.mortgagePaymentPercentage  按揭付款支付百分比
     * @apiSuccess (Success 200) {Integer} data.datas.mortgagePaymentLastDay  按揭付款自合同签订之日起XX日内付贷款
     * @apiSuccess (Success 200) {Double} data.datas.propertyFee  物业管理费
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/gets", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖条款信息详情查询", httpMethod = "POST")
    public TerminusResult<List<ContractSellClauseInfoResult>> gets(@RequestBody ContractSellClauseInfoGetsForm form) {
        ContractSellClauseInfoGetsParam param = BeanCopyUtils.copyProperties(form, ContractSellClauseInfoGetsParam.class);
        try {
            return contractSellClauseInfoService.gets(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询合同售卖条款信息失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询合同售卖条款信息失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellClauseInfo/query 合同售卖条款信息查询
     * @apiVersion 1.0.0
     * @apiGroup ContractSellClauseInfo
     * @apiName 合同售卖条款信息查询
     * @apiDescription 合同售卖条款信息查询
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Double} totalPrice  总价
     * @apiParam (RequestBody) {Double} unitPrice  单价
     * @apiParam (RequestBody) {String} paymentMethodCodeCode  付款方式code
     * @apiParam (RequestBody) {Integer} paymentDay  一次性付款/按揭付款天数范围
     * @apiParam (RequestBody) {String} paymentTypeCode  一次性付款/按揭付款时间类型 工作日，自然日，指定几号
     * @apiParam (RequestBody) {Double} mortgagePaymentPercentage  按揭付款支付百分比
     * @apiParam (RequestBody) {Integer} mortgagePaymentLastDay  按揭付款自合同签订之日起XX日内付贷款
     * @apiParam (RequestBody) {Double} propertyFee  物业管理费
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {Object[]} data.datas    合同售卖条款信息列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Double} data.datas.totalPrice  总价
     * @apiSuccess (Success 200) {Double} data.datas.unitPrice  单价
     * @apiSuccess (Success 200) {String} data.datas.paymentMethodCodeCode  付款方式code
     * @apiSuccess (Success 200) {Integer} data.datas.paymentDay  一次性付款/按揭付款天数范围
     * @apiSuccess (Success 200) {String} data.datas.paymentTypeCode  一次性付款/按揭付款时间类型 工作日，自然日，指定几号
     * @apiSuccess (Success 200) {Double} data.datas.mortgagePaymentPercentage  按揭付款支付百分比
     * @apiSuccess (Success 200) {Integer} data.datas.mortgagePaymentLastDay  按揭付款自合同签订之日起XX日内付贷款
     * @apiSuccess (Success 200) {Double} data.datas.propertyFee  物业管理费
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖条款信息查询", httpMethod = "POST")
    public TerminusResult<List<ContractSellClauseInfoResult>> query(@RequestBody ContractSellClauseInfoQueryForm form) {
        ContractSellClauseInfoQueryParam param = BeanCopyUtils.copyProperties(form, ContractSellClauseInfoQueryParam.class);
        try {
            return contractSellClauseInfoService.query(param, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("查询合同售卖条款信息失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("查询合同售卖条款信息失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

    /**
     * @api {POST} /contractSellClauseInfo/page 合同售卖条款信息分页查询
     * @apiVersion 1.0.0
     * @apiGroup ContractSellClauseInfo
     * @apiName 合同售卖条款信息分页查询
     * @apiDescription 合同售卖条款信息分页查询
     * @apiParam (RequestBody) {Long} contractId  合同ID
     * @apiParam (RequestBody) {Double} totalPrice  总价
     * @apiParam (RequestBody) {Double} unitPrice  单价
     * @apiParam (RequestBody) {String} paymentMethodCodeCode  付款方式code
     * @apiParam (RequestBody) {Integer} paymentDay  一次性付款/按揭付款天数范围
     * @apiParam (RequestBody) {String} paymentTypeCode  一次性付款/按揭付款时间类型 工作日，自然日，指定几号
     * @apiParam (RequestBody) {Double} mortgagePaymentPercentage  按揭付款支付百分比
     * @apiParam (RequestBody) {Integer} mortgagePaymentLastDay  按揭付款自合同签订之日起XX日内付贷款
     * @apiParam (RequestBody) {Double} propertyFee  物业管理费
     * @apiSuccess (Success 200) {Object} data    结果
     * @apiSuccess (Success 200) {long} data.pageSize    分页大小
     * @apiSuccess (Success 200) {long} data.currentPage    当前页
     * @apiSuccess (Success 200) {long} data.totalPages    总页数
     * @apiSuccess (Success 200) {long} data.totalRows    总记录数
     * @apiSuccess (Success 200) {long} data.minRowNumber    当页起始行号
     * @apiSuccess (Success 200) {long} data.maxRowNumber    当页最大行号
     * @apiSuccess (Success 200) {Object[]} data.datas    合同售卖条款信息列表
     * @apiSuccess (Success 200) {Long} data.datas.id  ID
     * @apiSuccess (Success 200) {Long} data.datas.contractId  合同ID
     * @apiSuccess (Success 200) {Double} data.datas.totalPrice  总价
     * @apiSuccess (Success 200) {Double} data.datas.unitPrice  单价
     * @apiSuccess (Success 200) {String} data.datas.paymentMethodCodeCode  付款方式code
     * @apiSuccess (Success 200) {Integer} data.datas.paymentDay  一次性付款/按揭付款天数范围
     * @apiSuccess (Success 200) {String} data.datas.paymentTypeCode  一次性付款/按揭付款时间类型 工作日，自然日，指定几号
     * @apiSuccess (Success 200) {Double} data.datas.mortgagePaymentPercentage  按揭付款支付百分比
     * @apiSuccess (Success 200) {Integer} data.datas.mortgagePaymentLastDay  按揭付款自合同签订之日起XX日内付贷款
     * @apiSuccess (Success 200) {Double} data.datas.propertyFee  物业管理费
     * @apiSuccessExample {json} 请求成功返回值:
     * {"code":"00000000","success":true,"message":"成功","data":[]}
     */
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiOperation(value = "合同售卖条款信息分页查询", httpMethod = "POST")
    public TerminusResult<TerminusPageAble<ContractSellClauseInfoResult>> page(@RequestBody ContractSellClauseInfoQueryForm form) {
        ContractSellClauseInfoQueryParam param = BeanCopyUtils.copyProperties(form, ContractSellClauseInfoQueryParam.class);
        try {
            TerminusPageInfo page = new TerminusPageInfo(form.getCurrentPage(), form.getRowsOfPage());
            return contractSellClauseInfoService.page(param, page, this.getTerminusContext());
        } catch (ServiceException e) {
            logger.error("分页查询合同售卖条款信息失败，原因：", e);
            return TerminusResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            logger.error("分页查询合同售卖条款信息失败，原因：", e);
            //todo 修改错误码
            return TerminusResult.fail("", this.getMessage(""));
        }
    }

}
